let usernameELe = document.getElementsByClassName('username')[0]
let passwordELe = document.getElementsByClassName('password')[0]
let rePassword = document.getElementsByClassName('re-password')[0]
let ageELe = document.getElementsByClassName('age')[0]
let genderEle = document.getElementsByClassName('gender')
let btnELe = document.getElementsByClassName('btn')[0]

let userNameChecked = false
usernameEle.unblur = function(){
  if(this.value){
    $.ajax({
      type:'get',
      url:'http://localost:30002/checkname',
      data:{
        username:this.value 
      },
      success:(result)=>{
        userNameChecked = (result.status === 'success')
        if(!userNameChecked){
          alert(result.messgae);
        }
      }
    })
  }
}
btnEle.onclick = ()=>{

  $.ajax({
    type:'post',
    url:'http://localhost:30002/userRegist',
    data:{
      username:usernameEle.value,
      password:passwordEle.value,
      age: ageELe.value
    },
    success:(result)=>{
      if(result.status === 'falied'){
        alert(result.messgae)
      }else{
        location.href = '/login'
      }
      
    }
  })
}